/********************************************************************************
Title: Data Preparation for Nepal Sample
		Define time points
		Define variables to use in each index
		Define survey round to use as reference round
********************************************************************************/


loc ref round == 5
*----------------------------------


use  "${raw}/nepal/nepal", clear
graph drop _all

*-------------------------------------------------------------------------------
*			0. Formating and Renaming Variables
*-------------------------------------------------------------------------------
gen month = month(date) - 8 + 12*year(date) - 12*2019
tab month

replace month = 1 if month == 0 
replace month = 4 if month == 5
replace month = 8 if month == 9
replace month = 10 if month == 11
drop if month == 13
label define monthl 1  "Sept 2019" 2 "Oct 2019" 3 "Nov 2019" 4 "Dec 2019" 8 "Apr-May 2020" ///
	10 "June-July 2020"  14 "Oct 2020"
label values month monthl
duplicates drop hhid round date, force
bysort hhid month (date): keep if _n == 1 //Note: this drops pretty much all of round 2. Right move?

*-------------------------------------------------------------------------------
*			1. Generating Variable Lists
*-------------------------------------------------------------------------------
macro drop depressed
gl depressed depressed stressed sleep 


*-------------------------------------------------------------------------------
*			2. Generating Indices
*-------------------------------------------------------------------------------
foreach g in  depressed {
	foreach var of varlist $`g' { 
	sum `var' if `ref'
	replace `var' = (`var' - `r(mean)')/`r(sd)'
	gen swt_`var' = `var'
	}
}

factor $depressed if `ref' , ipf factor(1)
predict ___depression_fw


gen day_seas = doy(date)
merge m:1 day_seas using "${raw}/nepal/nepal_seas", nogen

*-------------------------------------------------------------------------------
*          Unweighted indices
*-------------------------------------------------------------------------------
egen ___depression_nw = rowmean($depressed)


*-------------------------------------------------------------------------------
*          Inverse-covariance-weighted indices
*-------------------------------------------------------------------------------
icw_index($depressed), gen(___depression_icw)


reg ___depression_nw ses

